/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description: support batch module signatures verification
 * Author: xiongshenglan
 * Create: 2024-03-29
 */

#ifndef RTOS_MODULE_DIGEST_H
#define RTOS_MODULE_DIGEST_H

#include <linux/hashtable.h>
#include <linux/types.h>
#include <linux/spinlock_types.h>

#define KO_HASH_BITS 10
#define MAX_FILE_INPUT_LEN (10 * 1024 * 1024)
#define DEFAULT_KO_DIGEST_LIST_MAX 10000U

struct ko_digest_item {
	struct hlist_node hash_node; /* place in hash table */
	struct list_head list_node;  /* place in list for traversal */
	u8 *digest;                  /* always dim_digestsize() */
};

struct ko_digest_bulk {
	struct list_head list_head;                  /* for transverse */
	DECLARE_HASHTABLE(hash_head, KO_HASH_BITS); /* for hit */
	size_t digest_size;
	spinlock_t lock;
	size_t count;
	size_t max; /* when count >= max, no more baseline_item add into bulk */
};

extern bool module_found_digest(const void *buf, size_t mod_len, size_t sig_len);

#endif
